package com.raycloud.dao;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.raycloud.common.Result;
import com.raycloud.query.FrontProjectQuery;
import com.raycloud.pojo.FrontProject;

/**
 * @author  lvduo (lvduo940613@gmail.com)
 * @date    2017-04-27
 */

@Repository
public class FrontProjectDAO {

	@Resource
    SqlMapClientTemplate sqlMapClientTemplate;

	public Integer addFrontProject(FrontProject frontProject) {
		return (Integer)this.sqlMapClientTemplate.insert("FrontProject.insertFrontProject", frontProject);
	}

    /**
    * 根据主键查找
    
    */
    public FrontProject getFrontProjectByKey(     String projectName       )  {
                Map<String, Object> params = new HashMap<String, Object>();
            params.put("projectName", projectName);
                FrontProject result = (FrontProject) this.sqlMapClientTemplate.queryForObject(
                "FrontProject.getFrontProjectByKey", params);
        return result;
    }
    /**
     * 根据主键批量查找
     * @
     */
    public  List<FrontProject> getFrontProjectByKeys(    List<String> projectNameList    )  {
                Map<String, Object> params = new HashMap<String, Object>();
                    params.put("keys", projectNameList);
                        return  (List<FrontProject>)this.sqlMapClientTemplate.queryForList("FrontProject.getFrontProjectsByKeys", params);
    }
    /**
     * 根据主键删除
     * @return
     * @
     */
    public Integer deleteByKey(     String projectName       )  {
                Map<String, Object> params = new HashMap<String, Object>();
            params.put("projectName", projectName);
                Integer row = (Integer) this.sqlMapClientTemplate.delete("FrontProject.deleteByKey", params);
        return row;
    }
    /**
     * 根据主键批量删除
     * @return
     * @
     */
    public Integer deleteByKeys(    List<String> projectNameList    )  {
                Map<String, Object> params = new HashMap<String, Object>();
                    params.put("keys", projectNameList);
                       
        Integer row = (Integer) this.sqlMapClientTemplate.delete("FrontProject.deleteByKeys", params);
        return row;
    }
    /**
     * 根据主键更新
     * @return
     * @
     */
    public Integer updateFrontProjectByKey(FrontProject frontProject) {
		return (Integer) this.sqlMapClientTemplate.update("FrontProject.updateFrontProjectByKey", frontProject);
	}
    @SuppressWarnings("unchecked")
    public Result<FrontProject> getFrontProjectListWithPage(FrontProjectQuery frontProjectQuery){
	    Result<FrontProject> rs = new Result<FrontProject>();

            rs.setCount((Integer) this.sqlMapClientTemplate.queryForObject("FrontProject.getFrontProjectListCount",frontProjectQuery));
            if(frontProjectQuery.getFields()!=null&&frontProjectQuery.getFields()!=""){
                rs.setList((List<FrontProject>)this.sqlMapClientTemplate.queryForList("FrontProject.getFrontProjectListWithPageFields", frontProjectQuery));
            }else{
                rs.setList((List<FrontProject>)this.sqlMapClientTemplate.queryForList("FrontProject.getFrontProjectListWithPage", frontProjectQuery));
            }

		return rs;
	}

    @SuppressWarnings("unchecked")
    public List<FrontProject> getFrontProjectList(FrontProjectQuery frontProjectQuery) {
    if(frontProjectQuery.getFields()!=null&&frontProjectQuery.getFields()!=""){
        return (List<FrontProject>)this.sqlMapClientTemplate.queryForList("FrontProject.getFrontProjectListFields", frontProjectQuery);
    }
		return (List<FrontProject>)this.sqlMapClientTemplate.queryForList("FrontProject.getFrontProjectList", frontProjectQuery);
	}


}